package br.usjt.servico;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.DriverManager;

public class MySQLDAOFactory extends DAOFactory{
	private static String JDBC_DRIVER  = "com.mysql.jdbc.Driver";  
    private static String DATABASE_URL = "jdbc:mysql://localhost/videolocadora";  
    private static String LOGIN = "root";  
    private static String PASSWORD  = "";
	private static Connection conexao;
	 public static Connection criaConexao() {
	    	// socket de conexao
			conexao = null;
			try {
				if (conexao == null || conexao.isClosed()) {
					Class.forName(JDBC_DRIVER);
					// estabelece a conexao com o banco de dados
					conexao = DriverManager.getConnection(DATABASE_URL, LOGIN, PASSWORD);
				}
			} catch (ClassNotFoundException cnfex) {
				// excessoes para driver de conexao nao encontrado sao tratados aqui
				cnfex.printStackTrace();
			} catch (SQLException sqlex) {
				// excessoes do sql sao tratadas aqui
				sqlex.printStackTrace();
			} catch (Exception ex) {
				// process remaining Exceptions here
				ex.printStackTrace();
			}

			return conexao;
	    }
	@Override
	public IClienteDAO getClienteDAO() {
		return new MySQLClienteDAO();
	}
	@Override
	public IFilmeDAO getFilmeDAO() {
		return new MySQLFilmeDAO();
	}
	@Override
	public IUsuarioDAO getUsuarioDAO() {
		return new MySQLUsuarioDAO();
	}
}
